package com.ssg.poultry.servlet.admin;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ssg.poultry.entity.Poultry;
import com.ssg.poultry.servlet.BaseServlet;

@WebServlet("/admin/poultryInfo")
public class PoultryInfoServlet extends BaseServlet{
	
	private static final long serialVersionUID = 1L;
	private static Map<String,Poultry> all = new ConcurrentHashMap<>();
	
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
		super.init(config);
		Poultry p = new Poultry();
		p.setCardId("C5C3952A");
		p.setType("超级无敌原生态大鹅");
		p.setLocals(Arrays.asList("河南","北京","中关村","XX餐厅","34元卖出"));
		p.setImages(Arrays.asList("goose1.jpg","goose2.jpg","goose3.jpg","goose4.jpg","goose5.jpg"));
		all.put(p.getCardId(), p);
		
		//A4BAC066
		p = new Poultry();
		p.setCardId("A4BAC066");
		p.setType("红烧肉品种猪");
		p.setLocals(Arrays.asList("郑州","新乡","河南科技学院","三餐厅","红烧肉5块1碗"));
		p.setImages(Arrays.asList("pig1.jpg","pig2.jpg","pig3.jpg","pig4.jpg"));
		all.put(p.getCardId(), p);
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String cardid = req.getParameter("cardid");
		Poultry p = all.get(cardid);
		if(p == null) {
			resp.setContentType("text/plain;charset=utf8");
			resp.getWriter().println("未找到家禽："+cardid);
			return;
		}
		req.setAttribute("poultry", p);
		this.jsp("admin/poultryInfo");
	}
}
